//
//  PassValueViewController.swift
//  SwiftStudy
//
//  Created by wangtian on 15/7/14.
//  Copyright (c) 2015年 wangtian. All rights reserved.
//

import UIKit

class PassValueViewController: UIViewController, PassValueProtocol {

    @IBOutlet weak var testLabel: UILabel!
    fileprivate var myContext = 0
    override func viewDidLoad(){
        
        super.viewDidLoad()
        self.title = "类之间传值测试"
        NotificationCenter.default.addObserver(self, selector: #selector(PassValueViewController.passWordNotiFation(_:)), name: NSNotification.Name(rawValue: "PassWord"), object: nil)
        // Do any additional setup after loading the view.
    }
    
    func passWordNotiFation(_ noti:Notification){
    
        let obj:String = noti.object as! String
        print("notifation \(obj)")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func pushToNextpage(_ sender: UIButton) {
        
        let inputValueVC : InputValueViewController = self.storyboard!.instantiateViewController(withIdentifier: "InputValue") as!InputValueViewController
        
        inputValueVC.passValueBlock = {(passValue:String) ->(Void) in self.testLabel.text = passValue}
        inputValueVC.passValueDelegate = self
       // inputValueVC.addObserver(self, forKeyPath: "observerStr", options: NSKeyValueObservingOptions.New, context: &myContext)
        
        self.navigationController!.pushViewController(inputValueVC, animated: true)
    }
    
    func passValueFunc(_ needPassValue: String) {
        
        print("delegate \(needPassValue)")
    }

//    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
//        
//        print(change)
//    }
    
    deinit{
    
        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "PassWord"), object: nil)
    }
}
